/**
    ATClab - scriptable Air Traffic Control simulations.
    Copyright (C) 2010 openatclab@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/

#ifndef __AUDIO_PLAYER_HDR__
#define __AUDIO_PLAYER_HDR__


#include <qobject.h>
#include <qsound.h>

#include <deque>
#include <map>


#define SOUNDBITE       atc::AudioTrack*
#define SOUNDBITEDEQUE	std::deque<SOUNDBITE>
#define SOUNDBITEMAP	std::map<std::string,SOUNDBITE>


/*!
 *
 */
namespace atc {

	struct AudioTrack {
		AudioTrack( const std::string &name, int duration, bool prioity = false ) 
			: sound( QString(name.c_str()) ), length( duration ), priority( priority ) {}
		QSound sound;
		int    length;
		bool   priority;
	};


	/*!
	 *
	 */
	class AudioPlayer : public QObject {
		Q_OBJECT
	public:
		AudioPlayer( QObject * );
		~AudioPlayer();
	public:
		SOUNDBITE register_sound_bite( const std::string &, int, bool = false );
		void queue( SOUNDBITE );
	private slots:
		void play();
/*
	private:
#ifdef _WIN32
		int duration( const std::string & );
		std::string error_text(int, const char *);
#endif
*/
	private:
		SOUNDBITEMAP	_bites;
		SOUNDBITEDEQUE	_queue;
		bool            _finished;
	};

	/*!
	 *
	 */
	typedef SOUNDBITE    SoundBite;
	typedef SOUNDBITEMAP SoundBiteMap;

};


#undef SOUNDBITEMAP
#undef SOUNDBITEDEQUE
#undef SOUNDBITE

#endif
